home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-11-08 | 7.5 KB | 258 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWRadioB.cpp
- // Release Version: $ 1.0d11 $
- //
- // Copyright: © 1995 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "FWFrameW.hpp"
-
- #ifndef FWRADIOB_H
- #include "FWRadioB.h"
- #endif
-
- #ifndef FWFRAME_H
- #include "FWFrame.h"
- #endif
-
- #ifndef FWPART_H
- #include "FWPart.h"
- #endif
-
- // ----- OS Layer -----
-
- #ifndef FWEVENT_H
- #include "FWEvent.h"
- #endif
-
- #ifndef FWRRCSHP_H
- #include "FWRRcShp.h"
- #endif
-
- #ifndef FWODGEOM_H
- #include "FWODGeom.h"
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef SOM_ODSession_xh
- #include <ODSessn.xh>
- #endif
-
- #ifndef SOM_ODFacet_xh
- #include <Facet.xh>
- #endif
-
- #ifndef SOM_ODTransform_xh
- #include <Trnsform.xh>
- #endif
-
- //========================================================================================
- // Runtime Informations
- //========================================================================================
-
- #if FW_LIB_EXPORT_PRAGMAS
- #pragma lib_export on
- #endif
-
- #ifdef FW_BUILD_MAC
- #pragma segment fwgadgts
- #endif
-
- FW_DEFINE_CLASS_M1(FW_CRadioButton, FW_CButton)
-
- //========================================================================================
- // CLASS FW_CRadioButton
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_CRadioButton::FW_CRadioButton
- //----------------------------------------------------------------------------------------
-
- FW_CRadioButton::FW_CRadioButton(Environment* ev,
- FW_CView* container, ODID id,
- const FW_CRect& bounds,
- const FW_CString& label) :
- FW_CButton(ev, container, id, bounds),
- fButtonHelper(NULL)
- {
- #ifdef FW_BUILD_MAC
- fButtonHelper = new FW_CPrivMacRadioButtonHelper
- (ev, FW_TYPEID_FROM_TYPE(FW_CPrivMacRadioButtonHelper), this);
- #endif
-
- #ifdef FW_BUILD_WIN
- fButtonHelper = new FW_CPrivWinRadioButtonHelper
- (ev, FW_TYPEID_FROM_TYPE(FW_CPrivWinRadioButtonHelper), this);
- #endif
-
- fButtonHelper->SetText(label);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CRadioButton::~FW_CRadioButton
- //----------------------------------------------------------------------------------------
-
- FW_CRadioButton::~FW_CRadioButton()
- {
- delete fButtonHelper;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CRadioButton::LocationChanged
- //----------------------------------------------------------------------------------------
-
- void FW_CRadioButton::LocationChanged(Environment* ev,
- const FW_CPoint &oldLocation)
- {
- FW_UNUSED(oldLocation);
-
- #ifdef FW_BUILD_WIN
- FW_CViewContext fc(ev, this, GetFrame(ev)->GetActiveFacet(ev));
-
- FW_SPlatformPoint wndLocation = fc.ContentToCanvas(GetLocation(ev));
- FW_CPoint buttonSize = GetSize(ev);
- FW_SPlatformPoint wndSize = fc.ContentToCanvas(buttonSize.x, buttonSize.y);
- fButtonHelper->Move(wndLocation, wndSize);
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CRadioButton::SizeChanged
- //----------------------------------------------------------------------------------------
-
- void FW_CRadioButton::SizeChanged(Environment* ev, const FW_CPoint &oldSize)
- {
- FW_UNUSED(oldSize);
-
- #ifdef FW_BUILD_WIN
- FW_CViewContext fc(ev, this, GetFrame(ev)->GetActiveFacet(ev));
-
- FW_SPlatformPoint wndLocation = fc.ContentToCanvas(GetLocation(ev));
- FW_CPoint buttonSize = GetSize(ev);
- FW_SPlatformPoint wndSize = fc.ContentToCanvas(buttonSize.x, buttonSize.y);
- fButtonHelper->Move(wndLocation, wndSize);
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CRadioButton::Draw
- //----------------------------------------------------------------------------------------
-
- void FW_CRadioButton::Draw(Environment* ev, ODFacet* facet, ODShape* invalidShape)
- {
- #ifdef FW_BUILD_MAC
- FW_CViewContext gc(ev, this, facet, invalidShape);
-
- FW_SPlatformPoint qdPoint = gc.LogicalToDevice(FW_kZeroPoint);
- FW_SPlatformPoint qdSize;
- GetSize(ev).AsPlatformPoint(qdSize);
- ODPlatformWindow window = facet->GetWindow(ev)->GetPlatformWindow(ev);
- fButtonHelper->Draw(window, qdPoint, qdSize);
- #endif
-
- #ifdef FW_BUILD_WIN
- // Windows handles updating controls automatically
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CRadioButton::DoMouseDown
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_CRadioButton::DoMouseDown(Environment* ev, const FW_CMouseEvent& theMouseEvent)
- {
- // This code is duplicated for in each control class, think about moving it to the
- // control helpers, and maybe making the owner of helpers be gadgets. [AMB]
-
- #ifdef FW_BUILD_MAC
- ODFacet* odFacet = theMouseEvent.GetFacet(ev);
- FW_CViewContext gc(ev, this, odFacet);
-
- FW_CPoint canvasWhere = theMouseEvent.GetMousePosition(ev, FW_CMouseEvent::kWindow);
-
- {
- // Take into account the origin offset for pattern alignment. [AMB]
- FW_CAcquiredODTransform aqTransform(odFacet->CreateTransform(ev));
-
- ODPlatformCanvas plfmCanvas = gc.GetPlatformCanvas();
- FW_CPoint offset(
- FW_IntToFixed(plfmCanvas->portRect.left),
- FW_IntToFixed(plfmCanvas->portRect.top));
-
- ODPoint odOffset = offset;
- aqTransform->MoveBy(ev, &odOffset);
-
- canvasWhere.Transform(ev, aqTransform);
- }
-
- FW_SPlatformPoint qdControlPosition = gc.LogicalToDevice(FW_kZeroPoint);
- FW_SPlatformPoint qdWhere;
- canvasWhere.AsPlatformPoint(qdWhere);
- ODPlatformWindow window = odFacet->GetWindow(ev)->GetPlatformWindow(ev);
-
- FW_SPlatformPoint qdSize;
- GetSize(ev).AsPlatformPoint(qdSize);
-
- fButtonHelper->MouseDown(window, qdWhere, qdControlPosition, qdSize);
- return TRUE;
- #endif
-
- #ifdef FW_BUILD_WIN
- // Windows handles mouse events automatically
- return FALSE;
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CRadioButton::SetState
- //----------------------------------------------------------------------------------------
-
- void FW_CRadioButton::SetState(Environment* ev, FW_CViewContext& gc, FW_Boolean on)
- {
- #ifdef FW_BUILD_MAC
- ODPlatformWindow window = gc.GetFacet()->GetWindow(ev)->GetPlatformWindow(ev);
-
- FW_SPlatformPoint qdControlPosition = gc.LogicalToDevice(FW_kZeroPoint);
-
- FW_SPlatformPoint qdSize;
- GetSize(ev).AsPlatformPoint(qdSize);
-
- fButtonHelper->SetValue(window, qdControlPosition, qdSize, on ? 1 : 0);
- #endif
-
- #ifdef FW_BUILD_WIN
- SetState(ev, on);
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CRadioButton::SetState
- //----------------------------------------------------------------------------------------
-
- void FW_CRadioButton::SetState(Environment* ev, FW_Boolean on)
- {
- #ifdef FW_BUILD_MAC
- fButtonHelper->SetValue(on ? 1 : 0);
- #endif
-
- #ifdef FW_BUILD_WIN
- fButtonHelper->SetState(on ? 1 : 0);
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CRadioButton::ButtonPressed
- //----------------------------------------------------------------------------------------
-
- void FW_CRadioButton::ButtonPressed(Environment* ev)
- {
- // ----- Notify interested parties of that the button was pressed
-
- FW_CButtonPressedNotification notification(FW_CInterest(this, GetButtonPressedNotificationToken(ev)),
- GetIdentifier(ev), GetState(ev));
- Notify(notification);
- }
-